package com.yunshang.ys.utils;

//import com.risenbsy.ixing.api.my.MyFragmentApi;
//import com.risenbsy.ixing.dto.my.PhotoUrl;
//import com.risenbsy.risenbsylib.network.IXingSubscriber;
//import com.risenbsy.risenbsylib.network.RisHttp;

import com.yunshang.ys.api.DownImageApi;
import com.yunshang.ys.ys.YSHttp;
import com.yunshang.ys.ys.YSSubscriber;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/1/13.
 */

public class UploadPhotoUtil {


    /**
     * 上传file文件生成url文件
     */
    public void uploadPhoto(List<String> pathList, final OnComplete onComplete){

        List<MultipartBody.Part> multPartList = new ArrayList<>();

        final List<File> fileList = FileSizeUtil.getCompressedImagePaths(pathList);


        for (int i = 0; i < pathList.size(); i++) {
            multPartList.add(MultipartBody.Part.createFormData("file"+i,fileList.get(i).getName()
                    , RequestBody.create(MediaType.parse("image/*"), fileList.get(i))));
        }

        YSHttp.createApi(DownImageApi.class)
                .uploadImage(multPartList)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new YSSubscriber<String>() {
                    @Override
                    public void onSuccess(String t,String msg) {
                        System.out.println("rrrrrrrrrrrr " + t);
                        System.out.println("tttttttttttt " + msg);
                        onComplete.onSuccess(t,msg);
                    }
                    @Override
                    public void onFail(String msg) {
                        onComplete.onFail(msg);
                        System.out.println("msgmsgmsgmsg " + msg);
                    }
                });
    }



    public interface OnComplete{
        void onSuccess(String t,String msg);
        void onFail(String msg);
    }

}
